﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace msdcp
{
    public partial class SelectDateTimeDialog : Form
    {
        private DateTime dateTime;
        private readonly DateTime baseDate = new DateTime(2007, 1, 1);

        public DateTime DateTime
        {
            get { return dateTime; }
            set 
            {
                dateTime = value;
            }
        }

        public SelectDateTimeDialog()
        {
            InitializeComponent();
        }

        private void SelectDateTimeDialog_Shown(object sender, EventArgs e)
        {
            dateTimePicker1.Value = dateTime.Date;
            comboHours.SelectedIndex = dateTime.Hour;
            comboMinutes.SelectedIndex = dateTime.Minute;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string hoursText = comboHours.Text;
            string minutesText = comboMinutes.Text;
            int hours = int.Parse(hoursText);
            int minutes = int.Parse(minutesText);
            hours = Math.Max(0, Math.Min(hours, 23));
            minutes = Math.Max(0, Math.Min(minutes, 59));
            dateTime = dateTimePicker1.Value.Date;
            TimeSpan ts = new TimeSpan(hours, minutes, 0);
            dateTime += ts;
        }
    }
}
